package com.itoken.server.controller;

import com.google.common.collect.Lists;
import com.itoken.common.dto.BaseResult;
import com.itoken.server.domain.SysUser;
import com.itoken.server.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by 蔡超 on 2019/1/19.
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "login",method = RequestMethod.GET)
    public BaseResult login(@RequestParam(value = "username")String username, @RequestParam(value = "password")String password){

        if(StringUtils.isBlank(username) || StringUtils.isBlank(password)){
            return BaseResult.notOK(Lists.newArrayList(
                    new BaseResult.Error("username","用户名不能为空"),
                    new BaseResult.Error("password","密码不能为空")
            ));
        }

        SysUser sysUser = userService.login(username,password);
        return BaseResult.ok(sysUser);
    }

    @RequestMapping(value = "hi",method = RequestMethod.GET)
    public String sayHi(@RequestParam(value = "message") String message){
        return userService.sayHi(message);
    }


}
